﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LiveUpdate
{
    public partial class frmLiveUpdateLogin : Form
    {
        public frmLiveUpdateLogin()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            string sUser = txtUser.Text;
            string sPwd = txtPwd.Text;
            if ((sUser == "brs") && (sPwd == "brs"))
            {
                //-----------------Socket 
                string sDbServer = "";
                string sDbDatabase = "";
                string sDbUserID = "";
                string sDBPwd = "";
                string[] DbServerInfo;
                string SktIP = "";
                try
                {
                    IniFile iFile = new IniFile(Application.StartupPath + "\\SocketServer.ini");
                    SktIP = iFile.ReadString("SocketServer", "SktIP", "127.0.0.1");
                    string SktPort = iFile.ReadString("SocketServer", "SktPort", "6600");

                    SktClient SocketClint = new SktClient();
                    DbServerInfo = SocketClint.RequestDbInfo(SktIP, SktPort).Split(',');
                    sDbServer = DbServerInfo[0];
                    sDbDatabase = DbServerInfo[1];
                    sDbUserID = DbServerInfo[2];
                    sDBPwd = DbServerInfo[3].Replace("\0", "");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("连接服务器出错,错误原因为：" + ex.Message);
                    return;
                }
                if ((sDbServer == "") || (sDbDatabase == "") || (sDbUserID == "") || (sDBPwd == ""))
                {
                    MessageBox.Show("连接服务器出现错误,请重新连接");
                    return;
                }

                //TierService.Utility.SetConfigValue("App.xml", "Server", sDbServer);
                //TierService.Utility.SetConfigValue("App.xml", "database", sDbDatabase);
                //TierService.Utility.SetConfigValue("App.xml", "uid", sDbUserID);
                //TierService.Utility.SetConfigValue("App.xml", "pwd", DBUtility.CryptoHelper.Encode(sDBPwd));
                string _connectionString = "server=" + sDbServer + ";database=" + sDbDatabase + ";uid=" + sDbUserID + ";pwd=" + sDBPwd;
                DbHelperSQL.connectionString = _connectionString.Trim();

                //-----------------EndSocket

                frmLiveUpLoad mLiveUpLoad = new frmLiveUpLoad();
                mLiveUpLoad.ShowDialog();
                this.Close();
            }

        }
    }
}
